package com.dai.spec.gxk.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.dai.spec.common.core.domain.AjaxResult;
import com.dai.spec.common.utils.SecurityUtils;
import com.dai.spec.gxk.domain.Student;
import com.dai.spec.gxk.mapper.StudentMapper;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 学生信息 业务处理
 *
 * @author daikangle
 */
@SuppressWarnings("all")
@RestController
@RequestMapping("/system/student/profile")
public class StudentInfoController {
    private StudentMapper studentMapper;

    public StudentInfoController(StudentMapper studentMapper) {
        this.studentMapper = studentMapper;
    }

    /**
     * 学生信息
     */
    @GetMapping
    public AjaxResult profile() {
        String username = SecurityUtils.getLoginUser().getUsername();


            LambdaQueryWrapper<Student> queryWrapper = new LambdaQueryWrapper<>();
            queryWrapper.eq(Student::getStudentNumber, username);
            Student student = studentMapper.selectOne(queryWrapper);
            AjaxResult ajax = AjaxResult.success(student);
            if (student !=null) {
                ajax.put("studentNumber", username);
                ajax.put("age", student.getAge());
                ajax.put("courseCredits", student.getCourseCredit());
                ajax.put("skCredit", student.getSkCredit());
                ajax.put("zkCredit", student.getZkCredit());
                ajax.put("wyCredit", student.getWyCredit());
                ajax.put("ccCredit", student.getCcCredit());
            }

        return  ajax;


    }
}
